//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.carhailing.system.service.Impl;

import com.carhailing.common.domain.DriverUser;
import com.carhailing.common.requst.VerifyReq;
import com.carhailing.common.response.LiveResponse;
import com.carhailing.common.result.Result;
import com.carhailing.system.service.DriverUserService;
import com.carhailing.system.service.RegimentalService;
import com.carhailing.system.util.OssUtil;
import java.util.Date;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegimentalServiceImpl implements RegimentalService {
    private static final Logger log = LogManager.getLogger(RegimentalServiceImpl.class);
    @Autowired
    private OssUtil ossUtil;
    @Autowired
    private ThreadPoolExecutor threadPoolExecutor;
    @Autowired
    private DriverUserService driverUserService;

    public RegimentalServiceImpl() {
    }

    public Result authentication(DriverUser driverUser) throws Exception {
        CompletableFuture<VerifyReq> identCompletableFuture = CompletableFuture.supplyAsync(() -> {
            try {
                VerifyReq identity = this.ossUtil.identity(driverUser.getDriverCardId(), driverUser.getDriverName());
                log.info(identity);
                return identity;
            } catch (Exception var3) {
                throw new RuntimeException("身份证认证失败", var3);
            }
        }, this.threadPoolExecutor);
        CompletableFuture<LiveResponse> liveCompletableFuture = CompletableFuture.supplyAsync(() -> {
            try {
                LiveResponse liveResp = this.ossUtil.checkLife(driverUser.getDriverLife());
                return liveResp;
            } catch (Exception var3) {
                throw new RuntimeException("活体检测认证失败", var3);
            }
        }, this.threadPoolExecutor);
        CompletableFuture.allOf(identCompletableFuture, liveCompletableFuture).join();
        VerifyReq ident = (VerifyReq)identCompletableFuture.get();
        LiveResponse live = (LiveResponse)liveCompletableFuture.get();
        if (ident != null && live != null) {
            DriverUser user = this.driverUserService.DriverUserInfo();
            driverUser.setDriverPhone(user.getDriverPhone());
            driverUser.setDriverState(2);
            driverUser.setRegisterDate(new Date());
            this.driverUserService.save(driverUser);
            return Result.success("审核中");
        } else {
            return Result.error("认证失败");
        }
    }
}
